package cn.z2huo.demo.multidatasource.mybatisplus.dao;

import cn.z2huo.demo.mapper.user.UserMapper;
import cn.z2huo.demo.model.dataobject.user.UserDO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import jakarta.annotation.Nullable;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

/**
 * <p>
 *
 * @author z2huo
 */
@Repository
public class UserDAO {

    @Autowired
    private UserMapper userMapper;

    @Nullable
    public UserDO getUserByUserCode(String userCode) {
        if (StringUtils.isBlank(userCode)) {
            return null;
        }
        QueryWrapper<UserDO> queryWrapper = Wrappers.query(UserDO.class);
        queryWrapper.eq("user_code", userCode);
        return userMapper.selectOne(queryWrapper);
    }

    @Nullable
    public UserDO getUserByUserName(String userName) {
        if (StringUtils.isBlank(userName)) {
            return null;
        }
        LambdaQueryWrapper<UserDO> queryWrapper = Wrappers.lambdaQuery(UserDO.class);
        queryWrapper.eq(UserDO::getUserName, userName);
        return userMapper.selectOne(queryWrapper);
    }

}
